<template>
  <div class="app-container">
    <div class="app-form">
      <ele-form
        v-model="formData"
        v-bind="formConfig"
        :request-fn="handleRequest"
        @request-success="handleRequestSuccess"
      />
    </div>
  </div>
</template>

<script>
import { configBloc, configBlocSet, configUpdate } from '@projectName/views/diandi_place/api/place/config'
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      store_id: 0,
      formData: {
        status: 1
      },
      formConfig: {
        formDesc: {
          blocs: {
            type: 'cascader-bloc-store',
            label: '选择楼栋',
            on: {
              change: (val) => {
                console.log(val)
                this.store_id = val[1]
                this.getViews()
              }
            }
          },
          admin_ids: {
            type: 'input',
            label: '管理员'
          },
          mumber_scale: {
            type: 'input',
            label: '会员积分比例'
          },
          order_create_template: {
            type: 'input',
            label: '订单下单小程序订阅模板'
          },
          order_end_template: {
            type: 'input',
            label: '订单到期小程序订阅模板'
          },
          recharge_template: {
            type: 'input',
            label: '充值成功通知模板'
          },
          renew_template: {
            type: 'input',
            label: '续费通知模板'
          },
          sms_mobiles: {
            type: 'input',
            label: '短信通知手机号'
          },
          sms_order_sign: {
            type: 'input',
            label: '短信订单通知签名'
          },
          sms_order_template: {
            type: 'input',
            label: '短信订单通知模板'
          },
          store_introduce: {
            type: 'input',
            label: '商户简介'
          },
          index_thumb: {
            type: 'image-uploader',
            label: '首页图片'
          },
          vip_scale: {
            type: 'input',
            label: 'vip积分比例'
          },
          is_check_in: {
            type: 'radio',
            label: '是否公安核验',
            isOptions: true,
            default: 0,
            options: [
              {
                'text': '不核验',
                'value': 0
              },
              {
                'text': '核验',
                'value': 1
              }
            ]
          },
          wxapp_index_type: {
            type: 'radio',
            label: '小程序首页模板',
            isOptions: true,
            options: [
              {
                'text': '综合运营',
                'value': 1
              },
              {
                'text': '酒店',
                'value': 2
              },
              {
                'text': '民宿',
                'value': 3
              },
              {
                'text': '公寓',
                'value': 4
              }
            ]
          },
          maintain_time: {
            type: 'input',
            label: '房间维护时长/h',
            attrs: {
              type: 'number',
              step: '0.1',
              precision: 2
            }
          },
          befter_time: {
            type: 'input',
            label: '提前授权时长/h',
            attrs: {
              type: 'number',
              step: '0.1',
              precision: 2
            }
          },
          after_time: {
            type: 'input',
            label: '延迟授权时长/h',
            attrs: {
              type: 'number',
              step: '0.1',
              precision: 2
            }
          }
        },
        order: []
      }
    }
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  created() {
    const that = this
    that.store_id = that.userInfo.userInfo.store_id
    this.getViews()
  },
  methods: {
    getViews() {
      const store_id = this.store_id
      configBloc(store_id).then((res) => {
        this.formData = res.data.view || Object.assign({}, { blocs: this.formData.blocs })
      })
    },
    handleRequest(data) {
      if (data.blocs?.length) {
        data.bloc_id = data.blocs[0]
        data.store_id = data.blocs[1]
      }
      configBlocSet(data).then((response) => {
        if (response.code === 200) {
          this.$message.success(response.message)
        } else {
          this.$message.error(response.message)
        }
      })
      return Promise.resolve()
    },
    handleRequestSuccess() {},
    closePage() {
      this.$store.dispatch('app/closePage', {
        vm: this,
        fromName: this.$route.name,
        toName: 'diandi_hotel-hotel-config-index',
        params: {}
      })
    }
  }
}
</script>
